package edu.pucsp.predatorprey.tela;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.UIManager;

public class Tela {

	private JFrame frame;

	private PainelTerreno painelTerreno;

	private PainelInteracaoUsuario painelDireito;

	public Tela() {
		this.initComponents();
	}

	private void initComponents() {
		this.chooseLF();

		Modelo modelo = new Modelo();
		Controle controle = new Controle();
		controle.setModelo(modelo);
		PainelOpcoes opcoes = new PainelOpcoes(controle);
		PainelInformacoes informacoes = new PainelInformacoes(modelo);
		TerrenoCanvas canvas = new TerrenoCanvas(modelo);
		modelo.adicionarObservador(opcoes);
		modelo.adicionarObservador(informacoes);
		modelo.adicionarObservador(canvas);
		modelo.setPosicaoListener(canvas);

		this.painelTerreno = new PainelTerreno(canvas);
		this.painelDireito = new PainelInteracaoUsuario(opcoes, informacoes);

		this.frame = new JFrame("Predator-Prey");
		this.frame.setMinimumSize(new Dimension(900, 600));
		this.frame.setPreferredSize(new Dimension(900, 600));
		this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.frame.setLayout(new BorderLayout());
		this.frame.add(this.painelTerreno, BorderLayout.CENTER);
		this.frame.add(this.painelDireito, BorderLayout.EAST);
		this.frame.setLocationByPlatform(true);
	}

	private void chooseLF() {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			// OK, deve manter o look and feel default
		}
	}

	public void iniciar() {
		this.frame.setVisible(true);
	}

}
